﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebRole1
{
	public partial class Charts : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			GetPostsPerHour();

			GetPostsPerWeekday();

			//http://chart.apis.google.com/chart?chxt=x&cht=bvs&chco=76A4FB&chls=2.0&chs=400x205&chbh=r,0.3&chds=1&chxl=0:|sunday|monday|tuesday|wednesday|thursday|friday|saturday&chd=t:1,2,5,6,9,8,19
		}

		private void GetPostsPerHour()
		{
			Services.ChartService chartServ = new Services.ChartService();
			IList<KeyValuePair<int, int>> result = chartServ.GetPostsPerHour();

			string labelX = "&chxl=0:";
			string dataX = "&chd=t:";

			int i = 1;
			foreach (KeyValuePair<int, int> kvp in result)
			{
				labelX = labelX + "|" + kvp.Key.ToString();
				dataX = dataX + kvp.Value.ToString();
				if (i < result.Count)
				{
					dataX = dataX + ",";
				}

				i++;
			}

			string url = "http://chart.apis.google.com/chart?chxt=x&cht=bvs&chco=76A4FB&chls=2.0&chs=600x250&chbh=r,0.3&chds=1&chbh=10,10";
			url = url + labelX + dataX;

			imgChart_PostsPerHour.ImageUrl = url;
		}


		private void GetPostsPerWeekday()
		{
			Services.ChartService chartServ = new Services.ChartService();
			IList<KeyValuePair<string, int>> result = chartServ.GetPostsPerWeekday();

			string labelX = "&chxl=0:";
			string dataX = "&chd=t:";

			int i = 1;
			foreach (KeyValuePair<string, int> kvp in result)
			{
				labelX = labelX + "|" + kvp.Key;
				dataX = dataX + kvp.Value.ToString();
				if (i < result.Count)
				{
					dataX = dataX + ",";
				}

				i++;
			}

			string url = "http://chart.apis.google.com/chart?chxt=x&cht=bvs&chco=76A4FB&chls=2.0&chs=600x250&chbh=r,0.3&chds=1&chbh=10,63";
			url = url + labelX + dataX;

			imgChart_PostsPerWeekday.ImageUrl = url;
		}
	}
}